package com.example.shopingcenter.usercenter;

import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Build;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import androidx.annotation.RequiresApi;
import androidx.appcompat.app.AppCompatActivity;

import com.example.shopingcenter.DateBase.LoginDbHelper;
import com.example.shopingcenter.R;


public class UserCenterLogin extends AppCompatActivity {
    Button login, userrigster, userfoget;
    EditText lgid, lgpwd;



    @RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR1)
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_user_center_login);

        findView();


        login.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                   String name=lgid.getText().toString()    ;
                   String passrowd=lgpwd.getText().toString();

                 boolean result= LoginDbHelper.getInstance(UserCenterLogin.this).login(name,passrowd);
                 if (result){
                     startActivity(new Intent(UserCenterLogin.this, StartActivity.class));
                     Toast.makeText(UserCenterLogin.this, "登录成功", Toast.LENGTH_SHORT).show();
                     finish(); // 结束当前的登录Activity
                 }else {
                     Toast.makeText(UserCenterLogin.this, "登录失败,用户名或密码有误...", Toast.LENGTH_SHORT).show();
                 }

            }
        });
        userrigster.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(UserCenterLogin.this, Register.class);
                startActivity(intent);
            }
        });
        userfoget.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(UserCenterLogin.this, ForgetPassword.class);
                startActivity(intent);
            }
        });
    }

    private void findView() {
        login = findViewById(R.id.userlogin);
        lgid = findViewById(R.id.userid);
        lgpwd = findViewById(R.id.userpwd);
        userfoget = findViewById(R.id.userfoget);
        userrigster = findViewById(R.id.userrigster);
    }


}
